// pages/promote/promote.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
	shareImage:'',
	showShareGuide:false,
	cangohome:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
	  console.log('promote onLoad')
	  var self=this;	
		  const enterOptions = wx.getEnterOptionsSync(); // 获取本次进入小程序的场景值等信息
		  const { scene, path, shareTicket } = enterOptions;
		  if(scene == 1154){
			  console.log('promote:',scene)
		  }else{
			  const hasShownGuide = wx.getStorageSync('hasShownShareGuide');
			  if (!hasShownGuide) {
			        // 首次进入页面显示引导
			        this.setData({
			          showShareGuide: true
			        });
			        wx.setStorageSync('hasShownShareGuide', true);
			      }
				  this.setData({
					  cangohome:true
				  })
			  let aid = '';
				if(!aid){
				  aid=wx.getStorageSync('VP_AID');
				}
			  app.mdInit(function (cfg,mine,area) {
				self.setData({
					cfg: cfg,
					mine:mine,
					area:area,
					main_loaded:true
				});
			  },{
				aid:aid,
				fuid:'',
				stid:''
			  },true);
			this.getShareImage();
	  }
  },
  onShow() {
    if (wx.onShareTimeline) {
          // 隐藏一些交互元素，适应朋友圈单页模式
		  console.log('onShareTimeline')
        }
  },
  // 隐藏引导层
    hideShareGuide: function() {
      this.setData({
        showShareGuide: false
      });
    },
	gohome(){
		wx.switchTab({
			url:'/vp_pz/pages/index/index'
		})
	},
   onShareAppMessage: function () {
		  console.log(this.getSharePath());
		  return {
				  title: this.data.cfg.share_title?this.data.cfg.share_title:this.data.cfg.name,
				  imageUrl: this.data.cfg.share_image_url,
				  path: this.getSharePath()
		  }
  },
  getSharePath:function(){
          var page = app.mdName + '/pages/index/index';
          var ps = '?aid='+this.data.area.id+'&fuid=' + this.data.mine.id
          return page + ps;
  },
  onShareTimeline:function(){
	  return {
		  title: this.data.cfg.share_title?this.data.cfg.share_title:this.data.cfg.name,
		  imageUrl: this.data.shareImage
	  }
  },
  getShareImage:function(){
  	this.setData({
  		shareImage:'https://banyetang.oss-cn-beijing.aliyuncs.com/share/00'+this.getRandom1To8()+'.png'
  	})
  },
  getRandom1To8:function() {
  	return Math.floor(Math.random() * 8) + 1;
  },
})